using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;


public class EnemyAttackPreview : MonoBehaviour
{
    [SerializeField]
    public GameObject PreviewUIPrefab;
    public Transform imagePosition;
    private Transform imagesTransform;

    private PreviewImage thisPreviewImage;
    private void Start()
    {
        foreach (Canvas canvas in FindObjectsOfType<Canvas>())
        {
            if (canvas.renderMode == RenderMode.ScreenSpaceCamera)//查找方式可以不一样根据需求
            {
                imagesTransform=Instantiate(PreviewUIPrefab, canvas.transform).transform;
                thisPreviewImage = imagesTransform.GetComponent<PreviewImage>();
            }
        }
    }

    public void ShowAttackPreview(int num,int type)
    {
        //Debug.LogWarning(imagesTransform);//BUG：重新载入本场景这里会报null，在update里这个变量一直是有值的
        imagesTransform.gameObject.SetActive(true);
        thisPreviewImage.ChangeImage(type);
        thisPreviewImage.ChangeNumText(num);
    }

    public void HideCurrentPreview()
    {
        imagesTransform.gameObject.SetActive(false);
    }

    private void LateUpdate()
    {

        if (imagesTransform != null)
        {
            imagesTransform.position = imagePosition.position;
        }
    }
/*    private void Update()
    {
        Debug.Log(imagesTransform);
    }*/
}
